from app.aoduo_admin.models import AuthType
from common.authCheck.adminAuth import check_admin_login
from common.dictInfo import model_to_dict
from common.paginator import paginator
from django.http import JsonResponse
from rest_framework.views import APIView
from .chiefAdminAuthVerify import chiefAdminCheck
import json


class AdminAuthTypeInfoView(APIView):

    @check_admin_login
    @chiefAdminCheck
    def get(self, request):
        """
        获取权限列表
        :param request:
        :return:
        """
        allAuth = AuthType.objects.all()
        pageAllAuth = paginator(allAuth, request.GET.get('page'), 50)
        authDict = [model_to_dict(auth) for auth in pageAllAuth]
        return JsonResponse({
            'status': True,
            'auth': authDict,
            'has_previous': pageAllAuth.has_previous(),
            'has_next': pageAllAuth.has_next()
        })
